namespace QMVnSoft.SystemForms
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormUserPassword : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnOk;
        private IContainer components;
        private GroupBox groupBox4;
        private long ii_UserOrder;
        private LabelControl lblNewPass0;
        private LabelControl lblNewPass1;
        private LabelControl lblOldPass;
        private PictureBox pictureBox8;
        private TextControl txtNewPass0;
        private TextControl txtNewPass1;
        private TextControl txtOldPass;

        public FormUserPassword()
        {
            this.InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.OnSave();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.btnOk = new BtnControl();
            this.btnCancel = new BtnControl();
            this.lblOldPass = new LabelControl();
            this.txtOldPass = new TextControl();
            this.lblNewPass0 = new LabelControl();
            this.txtNewPass0 = new TextControl();
            this.lblNewPass1 = new LabelControl();
            this.txtNewPass1 = new TextControl();
            this.pictureBox8 = new PictureBox();
            this.groupBox4 = new GroupBox();
            ((ISupportInitialize) this.pictureBox8).BeginInit();
            base.SuspendLayout();
            this.btnOk.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnOk.Font = new Font("Arial", 8.25f);
            this.btnOk.Location = new Point(0xbf, 0x88);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new Size(0x4b, 0x17);
            this.btnOk.TabIndex = 3;
            this.btnOk.Text = "&Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new EventHandler(this.btnOk_Click);
            this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            //this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Font = new Font("Arial", 8.25f);
            this.btnCancel.Location = new Point(0x110, 0x88);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 4;
            this.btnCancel.Text = "&Hủy bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.lblOldPass.AutoSize = true;
            this.lblOldPass.Font = new Font("Arial", 8.25f);
            this.lblOldPass.Location = new Point(9, 0x16);
            this.lblOldPass.Name = "lblOldPass";
            this.lblOldPass.Size = new Size(0x41, 14);
            this.lblOldPass.TabIndex = 1;
            this.lblOldPass.Text = "Mật khẩu cũ";
            this.txtOldPass.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtOldPass.DisabledForeColor = Color.Empty;
            this.txtOldPass.Font = new Font("Arial", 8.25f);
            this.txtOldPass.Location = new Point(0x7a, 0x13);
            this.txtOldPass.MaxLength = 128;
            this.txtOldPass.Name = "txtOldPass";
            this.txtOldPass.Size = new Size(0xe1, 20);
            this.txtOldPass.TabIndex = 0;
            this.txtOldPass.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtOldPass.UserTrimMode = AppInstance.TextControlTrimMode.None;
            this.txtOldPass.UseSystemPasswordChar = true;
            this.lblNewPass0.AutoSize = true;
            this.lblNewPass0.Font = new Font("Arial", 8.25f);
            this.lblNewPass0.Location = new Point(9, 0x4b);
            this.lblNewPass0.Name = "lblNewPass0";
            this.lblNewPass0.Size = new Size(70, 14);
            this.lblNewPass0.TabIndex = 1;
            this.lblNewPass0.Text = "Mật khẩu mới";
            this.txtNewPass0.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtNewPass0.DisabledForeColor = Color.Empty;
            this.txtNewPass0.Font = new Font("Arial", 8.25f);
            this.txtNewPass0.Location = new Point(0x7a, 0x48);
            this.txtNewPass0.MaxLength = 128;
            this.txtNewPass0.Name = "txtNewPass0";
            this.txtNewPass0.Size = new Size(0xe1, 20);
            this.txtNewPass0.TabIndex = 1;
            this.txtNewPass0.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtNewPass0.UserTrimMode = AppInstance.TextControlTrimMode.None;
            this.txtNewPass0.UseSystemPasswordChar = true;
            this.lblNewPass1.AutoSize = true;
            this.lblNewPass1.Font = new Font("Arial", 8.25f);
            this.lblNewPass1.Location = new Point(9, 0x62);
            this.lblNewPass1.Name = "lblNewPass1";
            this.lblNewPass1.Size = new Size(0x6b, 14);
            this.lblNewPass1.TabIndex = 1;
            this.lblNewPass1.Text = "Khẳng định mật khẩu";
            this.txtNewPass1.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.txtNewPass1.DisabledForeColor = Color.Empty;
            this.txtNewPass1.Font = new Font("Arial", 8.25f);
            this.txtNewPass1.Location = new Point(0x7a, 0x5f);
            this.txtNewPass1.MaxLength = 128;
            this.txtNewPass1.Name = "txtNewPass1";
            this.txtNewPass1.Size = new Size(0xe1, 20);
            this.txtNewPass1.TabIndex = 2;
            this.txtNewPass1.UserTextLength = AppInstance.TextControlLength.ItemDescription;
            this.txtNewPass1.UserTrimMode = AppInstance.TextControlTrimMode.None;
            this.txtNewPass1.UseSystemPasswordChar = true;
            this.pictureBox8.Location = new Point(0x153, 0x30);
            this.pictureBox8.Name = "pictureBox8";
            this.pictureBox8.Size = new Size(10, 13);
            this.pictureBox8.TabIndex = 0x1a;
            this.pictureBox8.TabStop = false;
            this.groupBox4.Location = new Point(0x12, 0x36);
            this.groupBox4.Name = "groupBox4";
            this.groupBox4.Size = new Size(0x144, 2);
            this.groupBox4.TabIndex = 0x19;
            this.groupBox4.TabStop = false;
            this.groupBox4.Text = "groupBox4";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.CancelButton = this.btnCancel;
            base.ClientSize = new Size(0x167, 0xab);
            base.Controls.Add(this.pictureBox8);
            base.Controls.Add(this.groupBox4);
            base.Controls.Add(this.txtNewPass1);
            base.Controls.Add(this.lblNewPass1);
            base.Controls.Add(this.txtNewPass0);
            base.Controls.Add(this.lblNewPass0);
            base.Controls.Add(this.txtOldPass);
            base.Controls.Add(this.lblOldPass);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnOk);
            //base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FormUserPassword";
            base.ShowInTaskbar = false;
            this.Text = "Thay đổi mật khẩu";
            ((ISupportInitialize) this.pictureBox8).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void OnSave()
        {
            UserDataAccess access = new UserDataAccess();
            if (AppInstance.Password != this.txtOldPass.Text)
            {
                MessageBox.Show("Mật khẩu cũ không chính xác!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else if (this.txtNewPass0.Text != this.txtNewPass1.Text)
            {
                MessageBox.Show("Mật khẩu mới không hợp lệ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                access.ChangePassword(this.UserOrder, this.txtNewPass0.Text);
                base.Close();
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.OnSave();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        public long UserOrder
        {
            get
            {
                return this.ii_UserOrder;
            }
            set
            {
                this.ii_UserOrder = value;
            }
        }
    }
}

